package com.inspur.icity.bus.base.core.repo;


import com.inspur.icity.bus.base.core.util.AESUtil;
import org.apache.commons.dbcp.BasicDataSource;

import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

/**
 * 重置BasicDataSource
 *
 * Created by jn-dinggao on 2017/10/20.
 */
public class EncryptBasicDataSource extends BasicDataSource {
    org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EncryptBasicDataSource.class);

    public EncryptBasicDataSource(){
        super();
    }


    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {
        return null;
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return false;
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        return null;
    }

    @Override
    public void setPassword(String password){
        try{
            System.out.println("datasource password decrypt success !");
            this.password = AESUtil.Decrypt(password,AESUtil.AES_KEY);
        }catch(Exception e){
            logger.error("datasource password decrypt error !");
        }
    }
}
